package jbp.core;

import java.io.Serializable;

/**
 * 抽象实体基类，如果主键是数据库端自动生成
 * https://www.iteye.com/blog/silentwu-2124381
 */
public abstract class AbstractEntity<ID extends Serializable> implements Serializable {
    public abstract ID getId();
    public abstract void setId(final ID id);
    public boolean isNew() {
        return null == getId();
    }
    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!getClass().equals(obj.getClass())) {
            return false;
        }
        AbstractEntity<?> that = (AbstractEntity<?>) obj;
        return null == this.getId() ? false : this.getId().equals(that.getId());
    }

    @Override
    public int hashCode() {
        int hashCode = 17;
        hashCode += null == getId() ? 0 : getId().hashCode() * 31;
        return hashCode;
    }
}
